<template>
  <div class="task-progress-com" :disabled="isDisabled" v-if="isTaskProgressShow" @click="tapTo">
    <div class="progress-pic">
      <img :src="progressPic" alt />
    </div>
    <div class="progress-text">
      <p v-if="showFristP">任务审核失败：</p>
      <p>{{progressText}}</p>
    </div>
    <div class="progress-fold" v-show="progressFold">
      <img src="../assets/images/home_sign_more.png" alt />
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import mixin from '@/utils/mixin'
import onTask from '../assets/images/home_going.png'
import offTask from '../assets/images/home_failed.png'

export default {
  name: 'TaskProgress',
  mixins: [mixin],
  data () {
    return {
      isTaskProgressShow: false,
      progressPic: '',
      showFristP: false,
      progressText: '',
      progressFold: true,
      isDisabled: false,
      taskProStatusPro: {},
    }
  },
  watch: {
    taskProStatus (newVal) {
      this.taskProStatusPro = newVal
      this.changeCss()
    },
    failedReason () {
      this.changeCss()
      return this.failedReason
    }
  },
  props: {
    // 任务进度状态对象
    taskProStatus: {
      /**
       * resultCode：
       *  0-审核失败
       *  1-进行中
       */
      resultCode: Number,
      /**
       * resultSize：
       *  进行中任务数量
       */
      resultSize: Number,
      /**
       * resultRemark:
       *  失败的原因
       */
      resultRemark: String
    },
    /**
     * pageName:
     *  'taskIndex',
     *  'taskCourse',
     */
    pageName: String,
    /**
     * 审核失败的状态码
     */
    failedReason: Number
  },
  mounted () {
    this.changeCss()
  },
  methods: {
    tapTo () {
      sessionStorage.setItem('activeName','0')
      this.goUrl('/infMine/myTask')
    },
    changeCss () {
      if (this.pageName === 'taskIndex') {
        // console.log(this.taskProStatus)
        if (this.taskProStatusPro.resultCode === undefined) {
          this.isTaskProgressShow = false
        } else if (this.taskProStatusPro.resultCode === 0) {
          this.isTaskProgressShow = true
          this.progressPic = offTask
          this.showFristP = false
          this.progressText = '任务审核失败，请重新上传截图'
          this.progressFold = true
          this.isDisabled = false
        } else if (this.taskProStatusPro.resultCode === 1) {
          this.isTaskProgressShow = true
          this.progressPic = onTask
          this.showFristP = false
          this.progressText = `您有${this.taskProStatusPro.resultSize}条任务正在进行中…`
          this.progressFold = true
          this.isDisabled = false
        }
        return false
      }
      if (this.pageName === 'taskCourse') {
        if (this.failedReason === 0) {
          this.isTaskProgressShow = false
          return false
        }
        if (this.failedReason === 3) {
          // console.log(this.failedReason)
          this.isTaskProgressShow = true
          this.progressPic = offTask
          this.showFristP = true
          this.progressText = '上传的图片错误，请重新上传'
          this.progressFold = false
          this.isDisabled = false
          return false
        }
        // return false
      }
    }
  },
  components: {}
}
</script>

<style scoped lang="scss">
@import '~@/assets/css/common.scss';
img {
  // vertical-align: baseline !important;
  display: block;
}
.task-progress-com {
  width: 686px;
  background: rgba(255, 37, 37, 1);
  border-radius: 8px;
  margin-bottom: 24px;
  box-sizing: border-box;
  padding: 26px 32px;
  display: flex;
  justify-content: center;
  align-items: stretch;
  .progress-pic {
    width: 44px;
    img {
      margin-top: 5px;
      width: 44px;
      height: 44px;
    }
  }
  .progress-text {
    flex: 1;
    font-size: 34px;
    font-family: PingFangSC-Regular;
    font-weight: 400;
    color: rgba(255, 255, 255, 1);
    line-height: 48px;
    box-sizing: border-box;
    padding-left: 24px;
  }
  .progress-fold {
    width: 30px;
    img {
      margin-top: 10px;
      width: 30px;
      height: 30px;
    }
  }
}
</style>
